package com.lbs.demo.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/")
public class IndexController {

    @RequestMapping(method = RequestMethod.GET)
    public String get(HttpSession session){
        if(session.getAttribute("user")!=null){
            return "index";
        }
        else return "login";
    }

    @RequestMapping(value="index",method = RequestMethod.GET)
    public String get(ModelMap map, HttpSession session){
        if(session.getAttribute("user")!=null){
            return "index";
        }
        else return "login";
    }

    @RequestMapping(value = "name/{name}/{age}",method = RequestMethod.GET)
    public String getNameAge(ModelMap map, @PathVariable("name") String name, @PathVariable("age") int age){
        map.addAttribute("name",name);
        map.addAttribute("age",age);
        return "name";
    }


}
